package cn.tedu.boyou.acticle.service.impl;

import cn.tedu.boyou.acticle.domain.Strategy;
import cn.tedu.boyou.acticle.mapper.StrategyMapper;
import cn.tedu.boyou.acticle.service.IStrategyService;
import cn.tedu.boyou.common.query.StrategyQuery;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class StrategyServiceImpl implements IStrategyService {
    @Autowired
    private StrategyMapper strategyMapper;

    public PageInfo query(StrategyQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Strategy> regions = strategyMapper.selectForList(qo);
        return new PageInfo(regions);
    }

    public void saveOrUpdate(Strategy strategy) {
        if(strategy.getId() != null){
            strategyMapper.updateByPrimaryKey(strategy);
        }else{
            strategyMapper.insert(strategy);
        }

    }

    public void delete(Long id) {
        strategyMapper.deleteByPrimaryKey(id);
    }

    public List<Strategy> listAll() {
        return strategyMapper.selectAll();
    }
}
